import {
    shallowRef, defineAsyncComponent 
} from 'vue'
import {merge} from 'lodash'
export default function initCard(card = {}) {
    return merge({
        // 样式
        style: {
            top: 0,
            left: 0,
            width: 200,
            height: 200,
            rotate: 0,
        },
        // 交互
        interactive: {
            // 载入动画
            enterAnimation: {
                type: '',
                isOpacity: false,
                timingFunction: 'linear',
                direction: 'slideLeftSmall',
                duration: 300,
                delay: 0
            },
            // 回调函数
            callback: {
                active: '0',
                list: [
                    {
                        actions: {
                            active: 'click',
                            list: [
                                { label: "鼠标点击", value: 'click' }
                            ]
                        },
                        field: '',
                        variable: ''
                    }
                ]
            },
            // 自定义事件
            events: {
                active: '0',
                list: [
                    {
                        eventType: 'click',
                        actions: {
                            active: '0',
                            list: [
                                {

                                }
                            ]
                        }
                    }
                ]
            }
        },
        url: '',
        // 卡片
        component: card.component ? card.component : card.url ? shallowRef(defineAsyncComponent(() => {
            return new Promise(async r => {
                const VueDemo = await import(/* @vite-ignore */`${card.url}`)

                r(VueDemo)
            })
        })) : null,
        // 配置面板
        panelComponent: card.panelUrl ? shallowRef(defineAsyncComponent(() => {
            return new Promise(async r => {
                const VueDemo = await import(/* @vite-ignore */`${card.panelUrl}`)
                r(VueDemo)
            })
        })) : null,
        initProps: {}
    }, card, {deep: true})
}